package cn.edu.gzhmt.category.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import cn.edu.gzhmt.category.domain.Category;
import cn.edu.gzhmt.category.service.ICategoryService;
import cn.edu.gzhmt.category.service.impl.CategoryServiceImpl;
import cn.edu.gzhmt.utils.web.servlet.BaseServlet;

/**
 * 分类模块：web层
 * @author azhuo
 *
 */
public class CategoryServlet extends BaseServlet {

	private ICategoryService categoryService = new CategoryServiceImpl();

	/**
	 * 加载分类
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	public String loadCategory(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// 查询所有分类
		List<Category> categories = categoryService.findCategory();
		
		// 把数据转换成JSON格式，相应异步请求
		JSONArray jsonArray = JSONArray.fromObject(categories);
		response.getWriter().print(jsonArray.toString());
		
		return null;
	}
}
